/*
 * @lc app=leetcode id=66 lang=cpp
 *
 * [66] Plus One
 */
class Solution {
public:
    vector<int> plusOne(vector<int>& digits) {
        vector<int> v;
        int len = digits.size();
        if (len < 1) {
            return v;
        }

        v = digits;
        int adder = 1;
        int i = len-1;
        while(i>=0 && adder != 0) {
            adder = v[i]+adder;
            if (adder > 9) {
                v[i] = adder-10;
                adder = 1;
            } else {
                v[i] = adder;
                adder = 0;
                break;
            }
            i--;
        }
        if (adder) {
            v.insert(v.begin(), 1);
        }

        return v;
    }
};

